/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewCar.java
 *
 * Created on Jan 4, 2011, 8:28:35 PM
 */

package Graphic.DataManager.CarPackage;

import Client.RequestI;
import Data.Car;

/**
 *
 * @author Cristina
 */
public class NewCar extends javax.swing.JPanel {

    /** Creates new form NewCar */
    RequestI request = null;
    private int carId = 0;
    public NewCar(RequestI r) {
        request = r;
        initComponents();
        //carId.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        seatsNumberText = new javax.swing.JTextField();
        modelText = new javax.swing.JTextField();
        numberText = new javax.swing.JTextField();
        kmNumberText = new javax.swing.JTextField();
        maintenanceCostText = new javax.swing.JTextField();
        insertCarBtn = new javax.swing.JButton();
        insertCarLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        fuelText = new javax.swing.JTextField();

        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        setPreferredSize(new java.awt.Dimension(400, 300));

        seatsNumberText.setText("Seats Number");

        modelText.setText("Model");

        numberText.setText("Number");

        kmNumberText.setText("Km Number");

        maintenanceCostText.setText("Maintenance Cost");
        maintenanceCostText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maintenanceCostTextActionPerformed(evt);
            }
        });

        insertCarBtn.setText("Insert Car");
        insertCarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertCarBtnActionPerformed(evt);
            }
        });

        insertCarLabel.setFont(new java.awt.Font("Tahoma", 1, 18));
        insertCarLabel.setText("Insert new car:");

        jLabel3.setText("Number:");

        jLabel4.setText("Model:");

        jLabel5.setText("Seats Number:");

        jLabel6.setText("Km Number:");

        jLabel7.setText("Maintenance Cost:");

        jLabel8.setText("Fuel Consumption:");

        fuelText.setText("Fuel Consumption");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(161, 161, 161)
                        .addComponent(insertCarBtn))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8))
                                .addGap(73, 73, 73)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(fuelText)
                                    .addComponent(maintenanceCostText)
                                    .addComponent(kmNumberText)
                                    .addComponent(seatsNumberText)
                                    .addComponent(modelText)
                                    .addComponent(numberText, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)))
                            .addComponent(insertCarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(insertCarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(numberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(modelText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(seatsNumberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kmNumberText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maintenanceCostText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fuelText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addComponent(insertCarBtn)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void maintenanceCostTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maintenanceCostTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_maintenanceCostTextActionPerformed

    private void insertCarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertCarBtnActionPerformed
        String filename = null;
        if(insertCarBtn.getText().equalsIgnoreCase("Insert"))
        filename = request.insertCar("dmstc", new Car(numberText.getText(),
                    modelText.getText(), Integer.parseInt(seatsNumberText.getText()),
                    Integer.parseInt(kmNumberText.getText()), Double.parseDouble(maintenanceCostText.getText()),
                    Double.parseDouble(fuelText.getText())));
        else
            filename = request.editCar("dmstc", new Car(carId,numberText.getText(),
                    modelText.getText(), Integer.parseInt(seatsNumberText.getText()),
                    Integer.parseInt(kmNumberText.getText()), Double.parseDouble(maintenanceCostText.getText()),
                    Double.parseDouble(fuelText.getText())));
            request.getClient().SetRequest(filename);
    }//GEN-LAST:event_insertCarBtnActionPerformed

    public void setCar(Car car)
    {
        numberText.setText(car.getNumber());
        modelText.setText(car.getModel());
        seatsNumberText.setText(""+car.getSeatsNumber());
        kmNumberText.setText(""+car.getKmNumber());
        fuelText.setText(""+car.getFuelConsumption());
        maintenanceCostText.setText(""+car.getMaintenanceCost());
        //carId.setText(""+car.getCarId());
        carId = car.getCarId();
    }
    public void setNew()
    {
        numberText.setText("");
        modelText.setText("");
        seatsNumberText.setText("");
        kmNumberText.setText("");
        fuelText.setText("");
        maintenanceCostText.setText("");
        insertCarLabel.setText("Insert car");
        insertCarBtn.setText("Insert");

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField fuelText;
    public javax.swing.JButton insertCarBtn;
    public javax.swing.JLabel insertCarLabel;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField kmNumberText;
    private javax.swing.JTextField maintenanceCostText;
    private javax.swing.JTextField modelText;
    private javax.swing.JTextField numberText;
    private javax.swing.JTextField seatsNumberText;
    // End of variables declaration//GEN-END:variables

}
